﻿Chenxin.UI.EfficencyManage = Chenxin.extend(Chenxin.UI.PageCommon,{
    autoInitForm:false,
    actionUrl:'/service/logic/EfficencyManage.ashx',
    createSearch:function(){
        return new Chenxin.UI.EfficencyManageSearch({
            scope: this
        });
    },
    createGrid: function() {
        _this = this;
        return new Chenxin.UI.JsonGrid({
            createTitleTool: function() {
                return [{
                    text: '<span id="" class="x-grid-export" style="width:90px" title="导出全部数据">导出全部数据</span>',
                    scope: this,
                    title: '导出全部数据',
                    handler: function(el) {
                        _this.exportAll();
                    }
                }];
            },
            actionUrl: this.actionUrl + '?op=search',
            id: 'EfficencyManage_table',
            renderTo: 'EfficencyManage_table',
            hasCheckBox:false,
			cellBorder:true,
			scope:this,
			autoLoad: false,
			pageSize: 50,
			height: 400,
			modelId:'RecordId',
            columns: {
                RecordId:{
					create:false,
					head:'id'
				},
                City: {
                    head: '城市',
                    width: 50
                },
                Company: {
                    head: '公司',
                    width: 70
                },
                Businessdistrict: {
                    head: '商圈',
                    width: 100
                },
                Departs: {
                    head: '门店',
                    width: 120
                },
                EmployeeCode: {
                    head: '工号',
                    width: 100
                },
                Employee: {
                    head: '店长',
                    width: 70
                },
                PeopleNum: {
                    head: '店长人数',
                    width: 70
                },
                TotalNum: {
                    head: '店长总人数',
                    width: 80
                },
                YearMonth: {
                    head: '年月',
                    width: 70
                }
            }
        });
    },
    initEvent:function(){
        var _this = this;
       
        /*************************事件：人效计算************************/
        $("#aCalculate").click(function(){
            _this.calculate();
        });
        
        /*************************事件：查看店长************************/
        $("#aShowShoper").click(function(){
            if (_this.currentId == null || _this.currentId == "") {
                alert("请先选择一条记录！");
                return;
            }
            _this.loadShoperNum();
            _this.shoper();
        });
        
        /*************************事件：查看业务员************************/
        $("#aShowEmp").click(function(){
            if (_this.currentId == null || _this.currentId == "") {
                alert("请先选择一条记录！");
                return;
            }
            _this.loadEmpNum();
            _this.employee();
        });
        
//        /*************************事件：人效列表************************/
//        $("#aShowListEm").click(function(){
//            Chenxin.Fn.checkPermit(_this.actionUrl,'ShowListEm',function(data,msg){
//		        if(data.permit!=undefined){
//			        _this.permit=data.permit;	
//			        _this.msg = msg;
//		        }
//	        });
//	        if(objPreliminary.permit){			
//                window.location.href = "/page/Efficency_Manage/ShowListEmployee.aspx?op=search";
//	        }else{
//		        alert(_this.msg);
//	        }
//	    });
    },
    /**
    *人效计算
    */
    calculate:function(){
        var _this = this;
        if (!this.CalculateForm) {
            this.CalculateForm = new Chenxin.UI.CalculateForm({
                scrop: _this,
                alwaysCheckPermit: true,
                saveSucc:function(){
                    _this.grid.reload();
                    _this.currentId=null;
			    }
            });
        }
        this.CalculateForm.op = "calculate";
        if(this.CalculateForm.show(this.CalculateForm.op)){
            this.CalculateForm.reset();
            this.CalculateForm.setTitle('人效计算');
        }
    },
    /**
    *查看店长
    */
    shoper:function(){
        var _this = this;
        if (!this.ShoperNumDetailForm) {
            this.ShoperNumDetailForm = new Chenxin.UI.ShoperNumDetailForm({
                scrop: _this,
                title: '查看店长',
                alwaysCheckPermit: true,
                saveSucc:function(){
                    _this.grid.reload();
                    _this.currentId=null;
			    }
            });
        }
        if(this.ShoperNumDetailForm.show()){
		    var _shopernum = this.currentShoperNum;
            this.ShoperNumDetailForm.grid.clear();
            this.ShoperNumDetailForm.grid.render(_shopernum);
        }
    },
    /**
    *查看业务员
    */
    employee:function(){
        var _this = this;
        if (!this.EmpNumDetailForm) {
            this.EmpNumDetailForm = new Chenxin.UI.EmpNumDetailForm({
                scrop: _this,
                title: '查看业务员',
                alwaysCheckPermit: true,
                saveSucc:function(){
                    _this.grid.reload();
                    _this.currentId=null;
			    }
            });
        }
        if(this.EmpNumDetailForm.show()){
		    var _empnum = this.currentEmpNum;
            this.EmpNumDetailForm.grid.clear();
            this.EmpNumDetailForm.grid.render(_empnum);
        }
    },
    loadShoperNum: function() {
        var _this = this;
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: '/service/logic/EfficencyManage.ashx',
            data: { op: 'shoper',modelid: this.currentId},
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentShoperNum = data;
                }
            }
        });
    },
    loadEmpNum: function() {
        var _this = this;
        Chenxin.ajax({
            type: "get",
            dataType: "text",
            paramType: 'json',
            async: false,
            url: '/service/logic/EfficencyManage.ashx',
            data: { op: 'employee',modelid: this.currentId},
            onSuccess: function(data, msg) {
                if (data) {
                    _this.currentEmpNum = data;
                }
            }
        });
    },
    exportAll: function() {
            _this = this;
            paramStr = this.search.getParamJson();
            paramStr.op = 'exportAll';
            Chenxin.Msg.Waiting.show();
            Chenxin.Fn.exportToExcelByServer(this.actionUrl, paramStr, '导出文件');
            //$.ajax({ url: this.actionUrl, data: paramStr,async:false});
            Chenxin.Msg.Waiting.hide();
    }
});

/**
*查询面板
*/
Chenxin.UI.EfficencyManageSearch=Chenxin.extend(Chenxin.UI.SearchCommon,{
    id:'Efficency_search',
    initEvent:function(){
        var _this=this; 

        //查询按钮
        $('#btEfficency').click(function(){
              _this.scope.reloadGrid("",0);
        });
    },
    createComboList: function(){
        //月份
        var ComboMonth = new Chenxin.UI.Combo({
            containerId: '#month',
            tbxWidth: 15,
            colWidth: 15,
            items: comboCommon.EfficencyMonth
        });

        //五级联Combo
        var combl = new Chenxin.UI.StructComboList();
        var structs = combl.comboList;
        structs.push(ComboMonth);
        
        return structs;
    },
    initComponent: function() {
        Chenxin.UI.EfficencyManageSearch.superclass.initComponent.call(this);
    }
});

$(document).ready(function(){
    var efficencymanage = new Chenxin.UI.EfficencyManage();
});